import java.util.Scanner;

public class MT1151韩信生气 {
    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);
        // code here
        int n = 11;
        while (true){
            if(n %3 ==2 && n % 5 ==2 && n%7==2){
                System.out.println(n);
                break;
            }
            n++;
        }
        input.close();
    }
}
